package br.com.douglasramiro.controlefinanceiro.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Criptografia {
	public static String criptografar(String valor){
		MessageDigest md;
		try {
			md = MessageDigest.getInstance("SHA1");
			md.update(valor.getBytes());
	        byte[] newHash = md.digest();
	        StringBuffer newHashStringBuffer = new StringBuffer();
	        for ( int i = 0; i < newHash.length; i++ )
	            newHashStringBuffer.append(Integer.toHexString(newHash[i]&0xff));
	        return newHashStringBuffer.toString();
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return valor;
		}        
	}
}
